package com.atguigu.thread2;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CountDownLatchTest {
    private static Lock lock = new ReentrantLock();
    private static CountDownLatch countDownLatch = new CountDownLatch(6);

    public static void main(String[] args) {
        lock.lock();
        try{
            for (int i = 1; i < 8; i++) {
                int finalI = i;
                new Thread(()->{
                    System.out.println(finalI);
                    countDownLatch.countDown();
                },Thread.currentThread().getName()).start();
            }
            countDownLatch.await();
            System.out.println("chulaile");
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
}
